//
//  PinTuanViewController.m
//  1243
//
//  Created by ym on 16/6/27.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "PinTuanViewController.h"
#import "PingTuanTableViewCell.h"
#import "PinTuanXQViewController.h"
@interface PinTuanViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *btnArr;
    NSMutableArray *labelArr;
}
@property (nonatomic, strong) UISegmentedControl *segment;
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation PinTuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.translucent = NO;
    btnArr  = [NSMutableArray array];
    labelArr = [NSMutableArray array];
    self.title = @"拼团";
    [self CreattableView];
     [self creatLunbO];
}
- (void)creatLunbO{
    NSArray *image = @[
                       
                       [UIImage imageNamed:@"bot_1"],
                       [UIImage imageNamed:@"banner_bot1_boom"],
                       [UIImage imageNamed:@"bot_2"],
                       [UIImage imageNamed:@"bot_3"]
                       ];
    UIScrollView *scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 130)];
    scorllView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:scorllView];
    // 边缘弹动 效果 bounces
    scorllView.bounces = NO;
    // 整页翻动 pagingEnable
    scorllView.pagingEnabled = YES;
    // 允许滚动
    scorllView.scrollEnabled = YES;
    // 快速滚到当前页面顶端 (点击状态栏时) scrollToTop
    scorllView.scrollsToTop = YES;
    // 隐藏滚动条
    scorllView.showsHorizontalScrollIndicator = YES;  //横向
    scorllView.showsVerticalScrollIndicator = YES;   // 纵向s
    // 自定义滚动条样式
    scorllView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scorllView.contentSize = CGSizeMake(WIDTH * image.count, 130);
    
    for (NSInteger i = 0; i < image.count; i++) {
        UIImageView *a = [[UIImageView alloc] init];
        [scorllView addSubview:a];
        a.image = image[i];
        a.frame = CGRectMake(WIDTH *i, 0, WIDTH, 130);
    }
    
}

- (void)CreattableView{
    self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]  style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.contentInset = UIEdgeInsetsMake(130, 0, 0, 0);
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PinTuanXQViewController *a = [[PinTuanXQViewController alloc] init];
    [self pushForm:self.navigationController pushToAndHidden:a];
}
//tabBar 隐藏
- (void)pushForm:(UINavigationController *)pushForm pushToAndHidden:(UIViewController *)pushToVC
{
    [pushToVC setHidesBottomBarWhenPushed:YES];
    [pushForm pushViewController:pushToVC animated:YES];
    
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 25)];
    header.backgroundColor = [UIColor whiteColor];
    NSArray *arr = @[@"超值",@"进度",@"销量",@"最新"];
    for (NSInteger i  = 0; i < 4;  i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        [header addSubview:btn];
        btn.frame = CGRectMake(WIDTH / 4 * i, 5, WIDTH/4, 20);
        if (i == 0) {
            [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        }else{
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
        btn.tag = 1000+i;
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        [btnArr addObject:btn];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 4 * i + 15, 27, WIDTH / 4 - 30, 2)];
        [header addSubview:label];
        label.backgroundColor = [UIColor colorWithRed:45/255.0 green:87/255.0 blue:229/255.0 alpha:1];
        label.hidden = YES;
        label.tag = 2000 + i;
        [labelArr addObject:label];
        if (i == 0) {
            label.hidden = NO;
        }
    
    }
    
    
    return header;
}


- (void)btnAction:(UIButton *)sender{
    [sender setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    
    for (UIButton *btn in btnArr) {
        if (btn.tag == sender.tag) {
        }else{
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }
    for (UILabel *label in labelArr) {
        if (label.tag == sender.tag +1000) {
            label.hidden = NO;
        }else{
            label.hidden = YES;
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
#warning 头部
        static NSString *identifier= @"PingTuanTableViewCell";
        PingTuanTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"PingTuanTableViewCell" owner:nil options:nil] lastObject];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        return 310;
 
    
}

@end
